<?php
/**
 * Sea Framework
 * 
 * @author Feilong Li <yeephp@gmail.com>
 * @license New BSD License 
 * @version $Id: ValueStack.php 19 2010-09-29 16:33:07Z yeephp $
 */
/**
 * 应用生存时，变量stack
 *
 */
final class ValueStack {
	
	//通用信息
	private static $_data = array();
	//菜单，tab等状态控制信息
	private static $_widget = array();
	//模板赋值信息
	private static $_view = array();
	//上下文信息
	private static $_context = array();
	//导入路径
	private static $_import_path = array();
	//模型信息
	private static $_model = array();
	//配置信息
	private static $_config = array();
	//组件信息
	private static $_component = array();
	//模块信息
	private static $_module = array();
	
	/**
	 * Save 
	 *
	 * @param unknown_type $key
	 * @param unknown_type $value
	 */
	public static function set($key, $value) {
		$key = trim($key, '.');
		if (strpos($key, '.') !== false) {
			$tmp = explode('.', $key);
			$depth = count($tmp);
			switch ($depth) {
				case 1:
					self::$_data[$tmp[0]] = $value;
					break;
				case 2:
					self::$_data[$tmp[0]][$tmp[1]] = $value;
					break;
				case 3:
					self::$_data[$tmp[0]][$tmp[1]][$tmp[2]] = $value;
					break;
				case 4:
					self::$_data[$tmp[0]][$tmp[1]][$tmp[2]][$tmp[3]] = $value;
					break;
				default:
					$over = array_slice($tmp, 3);
					$tmp[3] = join('.', $over);
					self::$_data[$tmp[0]][$tmp[1]][$tmp[2]][$tmp[3]] = $value;
					break;
			}
		}else {
			self::$_data[$key] = $value;
		}
	}
	
	/**
	 * Get
	 *
	 * @param unknown_type $key
	 * @return unknown
	 */
	public static function get($key) {
		$key = trim($key, '.');
		if (strpos($key, '.') !== false) {
			$tmp = explode('.', $key);
			$depth = count($tmp);
			switch ($depth) {
				case 1:
					return isset(self::$_data[$tmp[0]]) ? self::$_data[$tmp[0]] : null ;
				case 2:
					return isset(self::$_data[$tmp[0]][$tmp[1]]) ? self::$_data[$tmp[0]][$tmp[1]] : null;
				case 3:
					return isset(self::$_data[$tmp[0]][$tmp[1]][$tmp[2]]) ? self::$_data[$tmp[0]][$tmp[1]][$tmp[2]] : null;
				case 4:
					return isset(self::$_data[$tmp[0]][$tmp[1]][$tmp[2]][$tmp[3]]) ? self::$_data[$tmp[0]][$tmp[1]][$tmp[2]][$tmp[3]] : null;
				default:
					$over = array_slice($tmp, 3);
					$tmp[3] = join('.', $over);
					return isset(self::$_data[$tmp[0]][$tmp[1]][$tmp[2]][$tmp[3]]) ? self::$_data[$tmp[0]][$tmp[1]][$tmp[2]][$tmp[3]] : null;
			}
		}else {
			return isset(self::$_data[$key]) ? self::$_data[$key] : null;
		}
	}
	
	
	public static function test() {
		print_r(self::$_data);
	}
	
	
}//end class

